package it.goc.adunanza;

import java.security.PublicKey;
import java.util.Properties;

import android.net.Uri;
import android.os.Build;
import android.os.Bundle;

import android.support.v7.app.ActionBarActivity;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import android.annotation.SuppressLint;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;



import javax.mail.FetchProfile;
import javax.mail.Folder;
import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Store;
import javax.mail.internet.InternetAddress;
import com.sun.mail.pop3.POP3Store;      





@SuppressLint("ShowToast")
public class MainActivity extends ActionBarActivity {
    public  void prova(View v){
      //creaNotifica(v);
      
      Intent msgIntent = new Intent(this, service48GOC.class);
      startService(msgIntent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }    

    public void creaNotifica(View v)
    {
        try{
       	  Context context= getApplicationContext(); 
        	  int icon = R.drawable.ic_launcher;
       	  long when = System.currentTimeMillis();
        	  NotificationManager nm=(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
         	  Intent intent=new Intent(context,MainActivity.class);
        	  PendingIntent  pending=PendingIntent.getActivity(context, 0, intent, 0);
       	  Notification notification;
          	  notification = null;
          	  final int soundResId = R.raw.notificatin_sound;
    	          notification = new Notification(icon, "[48 GOC] Adunanza", when);
     	          notification.setLatestEventInfo(context,
          	                    				"[48 GOC]",
          	                    				"Sei stato richiamato alle armi...muovi le chiappe e collegati!.",
          	                    				pending);
          	  notification.flags |= Notification.FLAG_AUTO_CANCEL;
       	  notification.sound = Uri.parse("android.resource://it.goc.adunanza/" + soundResId);
        	  nm.notify(0, notification);}              
         catch (Exception e) { 
              Log.e("readMail", e.getMessage(), e); 
          }    
 	   
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
    
   
	
} 

